/*
 *  Class name: TeamChooserDialogWindow.java
 *  Version: 1.0
 *  Date: 13.12.2013
 */
package cz.muni.fi.pa165.soccergamesarchive.restclient.gui.dialogs;

import cz.muni.fi.pa165.soccergamesarchive.businesslayer.dtos.TeamDTO;
import cz.muni.fi.pa165.soccergamesarchive.restclient.gui.components.enums.DialogWindowChoosedOption;
import cz.muni.fi.pa165.soccergamesarchive.restclient.gui.components.pageablelist.items.PageableListItemButton;
import cz.muni.fi.pa165.soccergamesarchive.restclient.utils.JOptionDialogWindowHandler;
import java.awt.Window;

/**
 *
 * @author Michal Ďuriš
 */
public class TeamChooserDialogWindow extends javax.swing.JDialog {

    private static final long serialVersionUID = 1L;

    private DialogWindowChoosedOption choosedOption = DialogWindowChoosedOption.CANCEL;

    /**
     * Creates new form TeamChooserDialogWindow
     *
     * @param owner
     * @param modalityType
     */
    public TeamChooserDialogWindow(Window owner, ModalityType modalityType) {
        super(owner, modalityType);

        initComponents();

        setLocationRelativeTo(owner);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonsPanel = new javax.swing.JPanel();
        actionButton = new javax.swing.JButton();
        cancelButton = new javax.swing.JButton();
        choosableTeamList = new cz.muni.fi.pa165.soccergamesarchive.restclient.gui.components.pageablelist.entity.ChoosableTeamList(getOwner(), "Teams");

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Choose a team");
        setPreferredSize(new java.awt.Dimension(250, 400));

        buttonsPanel.setPreferredSize(new java.awt.Dimension(250, 45));

        actionButton.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        actionButton.setText("Choose");
        actionButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                actionButtonActionPerformed(evt);
            }
        });

        cancelButton.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        cancelButton.setText("Cancel");
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout buttonsPanelLayout = new javax.swing.GroupLayout(buttonsPanel);
        buttonsPanel.setLayout(buttonsPanelLayout);
        buttonsPanelLayout.setHorizontalGroup(
            buttonsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, buttonsPanelLayout.createSequentialGroup()
                .addContainerGap(84, Short.MAX_VALUE)
                .addComponent(actionButton)
                .addGap(18, 18, 18)
                .addComponent(cancelButton)
                .addContainerGap())
        );

        buttonsPanelLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {actionButton, cancelButton});

        buttonsPanelLayout.setVerticalGroup(
            buttonsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, buttonsPanelLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(buttonsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(cancelButton)
                    .addComponent(actionButton))
                .addContainerGap())
        );

        buttonsPanelLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {actionButton, cancelButton});

        getContentPane().add(buttonsPanel, java.awt.BorderLayout.PAGE_END);

        choosableTeamList.init();
        getContentPane().add(choosableTeamList, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void actionButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_actionButtonActionPerformed
        handleActionButton();
    }//GEN-LAST:event_actionButtonActionPerformed

    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
        dispose();
    }//GEN-LAST:event_cancelButtonActionPerformed

    private void handleActionButton() {

        if (choosableTeamList.getSelectedItem() != null) {
            choosedOption = DialogWindowChoosedOption.OK;
            dispose();
        } else {
            JOptionDialogWindowHandler.showInfoDialogWindow(this, "Warning",
                    "Choose a team first !");
        }
    }

    public DialogWindowChoosedOption getChoosedOption() {
        return choosedOption;
    }

    public PageableListItemButton<TeamDTO> getSelectedItem() {
        return choosableTeamList.getSelectedItem();
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton actionButton;
    private javax.swing.JPanel buttonsPanel;
    private javax.swing.JButton cancelButton;
    private cz.muni.fi.pa165.soccergamesarchive.restclient.gui.components.pageablelist.entity.ChoosableTeamList choosableTeamList;
    // End of variables declaration//GEN-END:variables

}
